function MyLocalStoreUtil(key) {
	this.key = key;
}

MyLocalStoreUtil.prototype = {
	getLocalData() {
		let valueObj = null;
		const _this = this;
		const value = uni.getStorageSync(_this.key);
		if(value != '' && value != undefined) {
			valueObj = JSON.parse(value);
		}
		return valueObj;
	},
	setLocalData(value) {
		const _this = this;
		const data = _this.getLocalData();
		let dataList = [];
		
		if(data == null) {
			dataList.push(value);
		} else {
			data.forEach((item, index) => {
				if(item.id === value.id) {
					data.splice(index, 1);
				}
			});
			
			data.push(value);
			dataList = data;
		}
		
		uni.setStorageSync(_this.key, JSON.stringify(dataList));
	},
	delLocalData(value) {
		const _this = this;
		const data = _this.getLocalData();
		let dataList = [];
		console.log(data)
		if(data != null) {
			data.forEach((item, index) => {
				if(item.id === value.id) {
					data.splice(index, 1);
				}
			});
			console.log(data)
			dataList = data;
			
		}
		
		uni.setStorageSync(_this.key, JSON.stringify(dataList));
	},
	clearLocalData() {
		uni.clearStorageSync(_this.key);
	}
};



exports.MyLocalStoreUtil = MyLocalStoreUtil;
